package com.ctrip.demo.leetcode;

/**
 * @author xs.wu
 */
public class Leetcode1154 {


    public static void main(String[] args) {

        System.out.println(dayOfYear("2004-03-01"));

    }



    public static int dayOfYear(String date) {
        int res = 0;
        if(null == date || date.length() == 0) {
            return res;
        }
        char[] monthArr = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

        String[] dateArr = date.split("-");

        int year = Integer.parseInt(dateArr[0]);
        int month = Integer.parseInt(dateArr[1]);
        int day = Integer.parseInt(dateArr[2]);

        if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) monthArr[1]++;

        for(int i = 0; i < month - 1; i ++) {
            res += monthArr[i];
        }

        return res +day;

    }
}
